package com.waiting.leetcode;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @Description
 * @Author bjweitingting
 * @Date 2019/3/21
 **/
public class RevealCardInIncreasingOrder950 {
    public static void main(String[] args) {
        int[] nusm = {17, 13, 11, 2, 3, 5, 7};
        System.out.println(deckRevealedIncreasing(nusm
        ));
    }

    //
//    public int[] deckRevealedIncreasing(int[] deck) {
//        Arrays.sort(deck);
//        int[] nums = new int[deck.length];
//        int index = 0;
//        for (int i = 0; i < deck.length; i += 2) {
//            nums[i] = deck[index];
//            index++;
//        }
//        for (; index < deck.length; index++) {
//
//        }
//    }
    public static int[] deckRevealedIncreasing(int[] deck) {
        int n = deck.length;
        Arrays.sort(deck);
        //把每一个元素都放在了队列中
        Queue<Integer> q = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            q.add(i);
        }

        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[q.poll()] = deck[i];
            q.add(q.poll());
        }
        return res;
    }
}
